package lib

func init() {
	Probs = append(Probs, Problem{
		Num:         66,
		Discription: "给用数组表示的整数+1",
		Level:       1,
		Labels: map[string]int{
			"数学": 1,
		},
	})
}

func PlusOne(digits []int) []int {
	overflow := 0
	digits[len(digits)-1] += 1
	for i := len(digits) - 1; i >= 0; i-- {
		digits[i] += overflow
		if digits[i] >= 10 {
			overflow = 1
			digits[i] = 0
		} else {
			overflow = 0
			break
		}
	}

	//越界溢出的情况
	if overflow == 1 {
		return append([]int{1}, digits...)
	}

	return digits
}